package Thread;

import java.util.Scanner;


// 注意类名必须为 Main, 不要有任何 package xxx 信息
class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int num = in.nextInt();
        int[] arr = new int[num];
        for (int i = 0; i < num; i++) {
            arr[i] = in.nextInt();
        }
        arrGet = new int[num];
        System.out.println(smallSum(0, num - 1, arr));
    }

    public static int[] arrGet;

    private static long smallSum(int l, int r, int[] arr) {
        if (l == r) {
            return 0;
        }
        int m = (r + l) / 2;
        return smallSum(l, m, arr) + smallSum(m + 1, r, arr) + merge(l, m, r, arr);
    }

    private static long merge(int l, int m, int r, int[] arr) {
        long sum = 0;
        long ans = 0;
        int j = m + 1;
        int i = l;
        while (j <= r) {
            while (i <= m && arr[i] <= arr[j]) {
                sum += arr[i++];
            }
            ans += sum;
            j++;
        }
        int l1 = l;
        int l2 = m + 1;
        int r1 = m;
        int r2 = r;
        int count = l1;
        while (l1 <= r1 && l2 <= r2) {
            arrGet[count++] = (arr[l1] <= arr[l2]) ? arr[l1++] : arr[l2++];
        }
        while (l1 <= r1) {
            arrGet[count++] = arr[l1++];
        }
        while (l2 <= r2) {
            arrGet[count++] = arr[l2++];
        }
        for (int k = l; k <= r; k++) {
            arr[k] = arrGet[k];
        }
        return ans;
    }
}

public class Demo10 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = {2, 4, 3, 5, 1};
        System.out.println(solution.reversePairs(arr));
    }
}


class Solution {

    public int reversePairs(int[] nums) {
        int[] count = {0};
        newArr = new int[nums.length];
        reversePairs(0, nums.length - 1, nums, count);
        return count[0];
    }

    public static int[] newArr;

    private static void reversePairs(int l, int r, int[] arr, int[] count) {
        if (l == r) {
            return;
        }
        int mid = (l + r) / 2;
        reversePairs(l, mid, arr, count);
        reversePairs(mid + 1, r, arr, count);
        merge(l, r, mid, arr, count);
    }

    private static void merge(int l, int r, int mid, int[] arr, int[] count) {
        int ll = l;
        int i = l;
        int j = mid + 1;
        int sum = 0;
        while (i <= mid) {
            while (j <= r && (long) ((long) arr[i] - (long) arr[j]) > arr[j]) {
                sum++;
                j++;
            }
            count[0] += sum;
            i++;
        }
        int l1 = l;
        int l2 = mid + 1;
        while (l1 <= mid && l2 <= r) {
            newArr[l++] = (arr[l1] <= arr[l2]) ? (arr[l1++]) : (arr[l2++]);
        }
        while (l1 <= mid) {
            newArr[l++] = arr[l1++];
        }
        while (l2 <= r) {
            newArr[l++] = arr[l2++];
        }
        for (int k = ll; k <= r; k++) {
            arr[k] = newArr[k];
        }
    }
}